

namespace Header {
    public abstract class HttpHeader<VALUE> {
        public virtual string key {get; set;}
        public virtual VALUE value {get; set;}
        public abstract void parse_value(string value) throws HttpProtocolError;
        public abstract string build();
    }

    public class ContentLength : HttpHeader<uint64> {
        public const string KEY = "content-length";
        public override string key {get; set; default = KEY;}
        public override void parse_value (string value) throws HttpProtocolError {
            uint64 length;
            if (!uint64.try_parse(value, out length)) throw new HttpProtocolError.InvalidProtocol(@"Invalid contentn length value: $(value)");
            this.value = length;
        }
        public override string build() {
            return @"$key: $(this.value)";
        }
    }
    public class Generic : HttpHeader<string>{
        public const string KEY = "";
        public override void parse_value (string value) {
            this.value = value;
        }
        public override string build() {
            return @"$(key): $(this.value)";
        }
    }
    public class ContentType : HttpHeader<string> {
        public const string KEY = "content-type";
        public override string key {get; set; default = KEY;}
        public override void parse_value(string value) {
            this.value = value;
        }
        public override string build() {
            return @"$key: $(this.value); charset=utf-8";
        }
    }
}
